﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using KCL.Code;
using KCL.Code.Business;

namespace KCL.Components
{
    public partial class uscProduct : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            btnAddProduct.Enabled = dgvProduct.Columns[3].Visible = (bool)Session[SessionManager.canCreate];
            dgvProduct.Columns[2].Visible = (bool)Session[SessionManager.canModify];
            lblProductCode.Text = ProductServices.GetNextProductCode();
        }

        protected void btnAddProduct_Click(object sender, EventArgs e)
        {
            if (lblProductCode.Text.Trim().Length > 0 &&
                txtProductName.Text.Trim().Length > 0)
            {
                Product p = new Product();
                p.code = lblProductCode.Text.Trim();
                p.name = txtProductName.Text.Trim();
                p.isActive = true;
                ProductServices.Insert(p);
                dgvProduct.DataBind();
                dgvProduct.PageIndex = dgvProduct.PageCount - 1;
                lblProductCode.Text = ProductServices.GetNextProductCode();
            }
        }
    }
}